<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../js/layui/css/layui.css" media="all">
    <style type="text/css">
        .layui-table-cell{height:40px;line-height:40px;}
    </style>
</head>
<body>

<blockquote class="layui-elem-quote quoteBox mod_default_box">
    <form class="layui-form">
        <div class="layui-inline">
            <label class="layui-form-label">关键字</label>
            <div class="layui-input-inline">
                <input type="text" id="stu_name" name="stu_name" placeholder="请输入关键字" autocomplete="off" class="layui-input" />
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">日期</label>
            <div class="layui-input-inline">
                <input type="text" id="start_time" name="start_time" autocomplete="off" placeholder="请选择开始时间" class="layui-input">
            </div> 至
            <div class="layui-input-inline">
                <input type="text" id="end_time" name="end_time" autocomplete="off" placeholder="请选择结束时间" class="layui-input">
            </div>
        </div>
        <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="search-stu-submit">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
        </button>

        <div class="layui-inline">
            <label class="layui-form-label" style="width: 40px;">物业</label>
            <div class="layui-input-inline">
                <select name="city" lay-verify="" lay-filter="wuye" id="wuye" lay-search>
                    <option value="">选择物业</option>
                </select>
            </div>
        </div>
    </form>
</blockquote>
<!--数据列表-->
<table class="layui-hide" id="test" lay-filter="stu-table"></table>
<script type="text/html" id="tb">
    <div class="layui-container" style="margin-left:0px;">
        <a class="layui-btn layui-btn-xs" id="exportExcel">导出Excel</a>
    </div>
</script>
<script type="text/html" id="stu-toolbar">
    <a class="layui-btn layui-btn-xs" lay-event="detail">详细记录</a>
    <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
</script>
<script src="../../js/layui/layui.js"></script>
<script src="../../js/layui/layui.all.js"></script>
<script src="../../js/token.js"></script>
<script src="../../js/config.js"></script>

<script>
    layui.use(['table','upload'], function(){
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var wyId = "";
        table.render({
            elem: '#test'
            ,id:'stu-table-id'//重载需要
            ,url:HOST+'business/getBusinessStatistics'
            ,title:'商户表'
            ,toolbar: '#tb'
            ,cols: [[
                {type:'numbers', title: '序号'}
                ,{field:'wyName',align : 'center',width : 180, title: '物业名称'}
                ,{field:'business_name',align : 'center',width : 220, title: '商户名称'}
                ,{field:'business_bh',align : 'center',width : 125,title: '商户编号'}
                ,{field:'access_date',align : 'center', width : 160,title: '日期',templet : "<div>{{layui.util.toDateString(d.access_date, 'yyyy-MM-dd')}}</div>"}
                ,{field:'access_count',align : 'center', width : 125,title: '访问人数'}
                ,{toolbar:"#stu-toolbar",align : 'center',width:160,title:"操作",fixed: 'right'}
            ]]
            ,page: true
            ,page: {
                curr: layui.data("business_statistics_page").index
            },
            done: (res, curr, count) => {
                layui.data("business_statistics_page", {
                    key: 'index',
                    value: curr
                });
                bindClick();
            }
        });

        $.ajax({
            url:HOST+"wuye/selectwuyestatus" ,
            success:function(res){
                if(res.code == 0) {
                    for(var i in res.data) {
                        $("#wuye").append("<option value='"+res.data[i].id+"'>"+res.data[i].wyname+"</option>")
                    }
                    form.render()
                }
            }
        })

        //搜索操作
        form.on('submit(search-stu-submit)',function (data) {
            var start_time = $("#start_time").val();
            var end_time = $("#end_time").val();
            table.reload('stu-table-id',{
                where:{"name":data.field.stu_name,"start_time":start_time,"end_time":end_time, "wyId":wyId}
                ,page:{
                    curr:1
                }
            });
            return false;
        });

        form.on('select(wuye)', function(data){
            wyId = data.value
            var start_time = $("#start_time").val();
            var end_time = $("#end_time").val();
            var name = $("#stu_name").val();
            table.reload('stu-table-id', {
                where:{"name":name,"start_time":start_time,"end_time":end_time, "wyId":wyId}
                , page: {
                    curr: 1
                }
            });
        });

        //表操作  监听操作
        table.on('tool(stu-table)',function (obj) {
            var data=obj.data;
            var event=obj.event;
            if(event==='detail'){
                layer.open({
                    type:2
                    ,title:"详细记录"
                    ,skin:'layui-layer-molv'
                    ,area: ['95%', '95%'],
                    content:("business_statistics_detail.html?id="+data.id+"&business_bh="+data.business_bh+"&access_date="+data.access_date)
                    //content:$('#update-stu-layer')
                });
            }
        });

        function bindClick() {
            $('#exportExcel').on('click',function () {
                var name = $("#stu_name").val();
                var start_time = $("#start_time").val();
                var end_time = $("#end_time").val();
                $("#exportExcel").attr('href',HOST+"business/exportExcelByBusinessStatistics?name=" + name + "&start_time=" + start_time + "&end_time=" + end_time + "&wyId=" + wyId);
            });
        }

    });
</script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        var endDate= laydate.render({
            elem: '#end_time',//选择器结束时间
            type: 'date',
            min:"1970-1-1",//设置min默认最小值
            done: function(value,date){
                startDate.config.max={
                    year:date.year,
                    month:date.month-1,//关键
                    date: date.date,
                }
            }
        });
        //日期范围
        var startDate=laydate.render({
            elem: '#start_time',
            type: 'date',
            max:"2099-12-31",//设置一个默认最大值
            done: function(value, date){
                endDate.config.min ={
                    year:date.year,
                    month:date.month-1, //关键
                    date: date.date,
                };
            }
        });
    });
</script>
</body>
</html>